/**
 * @param {number[]} people
 * @param {number} limit
 * @return {number}
 */
var numRescueBoats = function (people, limit) {
  people.sort((a,b)=>a-b)
  let left=0,right=people.length-1,count=0
  while(left<=right){
    if(people[left]+people[right]<=limit){
      left++
    }
    right--
    count++
  }
  return count
}

numRescueBoats([1,1,2,3], 3)
